use "$dir\DataSCLB", clear
	// Get average by treatment to add up
		sum MT_S0_glmnet
		local MT_mean = r(mean)
		sum CCT_S0_glmnet
		local CCT_mean = r(mean)
		gen 	EL_EGRA_PCA_Index_glmnet_S0 = EL_EGRA_PCA_Index 				 if Study_Arm == 0
		replace EL_EGRA_PCA_Index_glmnet_S0 = EL_EGRA_PCA_Index - CCT_S0_glmnet + `CCT_mean' if Study_Arm == 1
		replace EL_EGRA_PCA_Index_glmnet_S0 = EL_EGRA_PCA_Index - MT_S0_glmnet  + `MT_mean'  if Study_Arm == 2
	// Testing TE
	reg EL_EGRA_PCA_Index_glmnet_S0 MT_Program CCT_Program,  cluster(School_blind) 

	// Estimate Bounds
	set seed 67296786
	fhbounds EL_EGRA_PCA_Index_glmnet_S0, r(1000) treatment(MT_Program CCT_Program) control(Control) strata(Group_blind) cluster(School_blind) bias  
	keep if p==5 | p==25 | p==50 | p==75 | p==95  | (p>99)
	
	keep p_exp *_st i p sortvar
	
	save "$output/Table7.dta", replace

	
	
		keep p i *lo* 
			keep if p<100
			egen group = group(p)
			gsort - group i
			gen sortvar = _n
			rename FH_lo_MT_Program_pt_st  FH_lo_MT_Program_pt_st_rev
			rename FH_lo_CCT_Program_pt_st FH_lo_CCT_Program_pt_st_rev
			tempfile reverse
			save `reverse'
			use "$output/Table7.dta", clear
			drop sortvar
			gen sortvar = _n
			qui merge 1:1 sortvar using `reverse', keepusing(*_rev)
			qui replace FH_lo_MT_Program_pt_st = FH_lo_MT_Program_pt_st_rev if _merge==3
			qui replace FH_lo_CCT_Program_pt_st = FH_lo_CCT_Program_pt_st_rev if _merge==3
			
			replace p = 100 if p==102
			replace p = 100.5 if p==103
			sort p i
			drop _merge FH_lo_MT_Program_pt_st_rev FH_lo_CCT_Program_pt_st_rev sortvar i p
	gen blank =""		
			
# delimit ;			
texsave p_exp FH_up_MT_Program_pt_st FH_lo_MT_Program_pt_st blank FH_up_CCT_Program_pt_st FH_lo_CCT_Program_pt_st using "$output/T7.tex", 
					replace align(rccccc) location(H) width(\textwidth) hlines(10)
					headerlines("& \multicolumn{2}{c}{Full-cost Program} & & \multicolumn{2}{c}{Reduced-cost Program} \\ 
					\cmidrule{2-3} \cmidrule{5-6} & Rank & Rank & & Rank & Rank \\ 
					& Preservation & Inversion & & Preservation   & Inversion \\
					& (1) & (2) & & (3) & (4) ") 
					marker(tb:fhbounds) title(\\ Fréchet-Höffding Bounds) 
					size(small) frag nonames nofix ;
# delimit cr					